repo: Create uncompressed-object-cache dir dynamically
authorColin Walters <walters@verbum.org>
Tue, 6 Feb 2018 15:13:46 +0000 (10:13 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 8 Feb 2018 21:27:11 +0000 (21:27 +0000)
Having the `uncompressed-object-cache` directory in `archive` repos by default
is clutter; the functionality should be considered deprecated.

Now we only create the directory if we're doing a checkout with the cache
enabled.

Closes: #1446
Approved by: jlebon

src/libostree/ostree-repo-checkout.c
src/libostree/ostree-repo.c
tests/basic-test.sh

index 45d5c3277a33b8be66bf0bd3813ef8b858faf937..6317c9e85ecc85617fa3825ae02694a3bd5e6558 100644 (file)
@@ -89,6 +89,17 @@ checkout_object_for_uncompressed_cache (OstreeRepo      *self,
   if (!glnx_fchmod (tmpf.fd, file_mode, error))
     return FALSE;
 
+  if (self->uncompressed_objects_dir_fd == -1)
+    {
+      if (!glnx_shutil_mkdir_p_at (self->repo_dir_fd, "uncompressed-objects-cache", 0755,
+                                   cancellable, error))
+        return FALSE;
+      if (!glnx_opendirat (self->repo_dir_fd, "uncompressed-objects-cache", TRUE,
+                           &self->uncompressed_objects_dir_fd,
+                           error))
+        return FALSE;
+    }
+
   if (!_ostree_repo_ensure_loose_objdir_at (self->uncompressed_objects_dir_fd,
                                             loose_path,
                                             cancellable, error))
@@ -420,7 +431,11 @@ checkout_file_hardlink (OstreeRepo                          *self,
   int srcfd = _ostree_repo_mode_is_bare (self->mode) ?
     self->objects_dir_fd : self->uncompressed_objects_dir_fd;
 
-  if (linkat (srcfd, loose_path, destination_dfd, destination_name, 0) == 0)
+  if (srcfd == -1)
+    {
+      /* Fall through; we don't have an uncompressed object cache */
+    }
+  else if (linkat (srcfd, loose_path, destination_dfd, destination_name, 0) == 0)
     ret_result = HARDLINK_RESULT_LINKED;
   else if (!options->no_copy_fallback && (errno == EMLINK || errno == EXDEV || errno == EPERM))
     {
@@ -430,6 +445,7 @@ checkout_file_hardlink (OstreeRepo                          *self,
     }
   else if (allow_noent && errno == ENOENT)
     {
+      /* Fall through */
     }
   else if (errno == EEXIST)
     {
@@ -1071,6 +1087,19 @@ checkout_tree_at (OstreeRepo                        *self,
         }
     }
 
+  /* Uncompressed archive caches; should be considered deprecated */
+  const gboolean can_cache = (options->enable_uncompressed_cache
+                              && self->enable_uncompressed_cache);
+  if (can_cache
+      && !_ostree_repo_mode_is_bare (self->mode)
+      && self->uncompressed_objects_dir_fd < 0)
+    {
+      self->uncompressed_objects_dir_fd =
+        glnx_opendirat_with_errno (self->repo_dir_fd, "uncompressed-objects-cache", TRUE);
+      if (self->uncompressed_objects_dir_fd < 0 && errno != ENOENT)
+        return glnx_throw_errno_prefix (error, "opendir(uncompressed-objects-cache)");
+    }
+
   /* Special case handling for subpath of a non-directory */
   if (g_file_info_get_file_type (source_info) != G_FILE_TYPE_DIRECTORY)
     {
index 23ae75b3f224e0a0645cf97557ab4b1ab49665aa..9242990cb5bda64c3ddcd7d5aa8774679dc86f8a 100644 (file)
@@ -3029,18 +3029,6 @@ ostree_repo_open (OstreeRepo    *self,
   if (!ostree_repo_reload_config (self, cancellable, error))
     return FALSE;
 
-  /* TODO - delete this */
-  if (self->mode == OSTREE_REPO_MODE_ARCHIVE && self->enable_uncompressed_cache)
-    {
-      if (!glnx_shutil_mkdir_p_at (self->repo_dir_fd, "uncompressed-objects-cache", 0755,
-                                   cancellable, error))
-        return FALSE;
-      if (!glnx_opendirat (self->repo_dir_fd, "uncompressed-objects-cache", TRUE,
-                           &self->uncompressed_objects_dir_fd,
-                           error))
-        return FALSE;
-    }
-
   self->inited = TRUE;
   return TRUE;
 }
index 0046558ec2cc5d8b0c5ae49062d4fd11c230cf80..530efd0a137d5de92898847aa9e0f63c9fad0f05 100644 (file)
@@ -42,6 +42,9 @@ else
     fi
 fi
 
+# This should be dynamic now
+assert_not_has_dir repo/uncompressed-objects-cache
+
 validate_checkout_basic() {
     (cd $1;
      assert_has_file firstfile